//
//  DKUnauthorizedProductStepView.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/24.
//

#import "DKUnauthorizedProductStepView.h"
@interface DKUnauthorizedProductStepView()
@property (nonatomic, strong)UIButton * applicationBtn;
@property (nonatomic, strong)UIButton * billBtn;
@property (nonatomic, strong)UIButton * historyBtn;
@end
@implementation DKUnauthorizedProductStepView


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame: frame]) {
        [self creatUI];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showBillSelect) name:@"RefreshTable" object:nil];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showAppSelect) name:@"RefreshAppTable" object:nil];
    }
    return self;
}

-(void)showBillSelect{
    self.applicationBtn.selected = NO;
    self.billBtn.selected = YES;
    self.historyBtn.selected = NO;
    [self.delagate DKUnauthorizedProductSelectedIndex:2];
}
-(void)showAppSelect{
    self.applicationBtn.selected = YES;
    self.billBtn.selected = NO;
    self.historyBtn.selected = NO;
    [self.delagate DKUnauthorizedProductSelectedIndex:1];
}
-(void)setType:(NSInteger)Type{
    _Type = Type;
    UIButton * sender = [self viewWithTag:_Type];
    [self btnAction:sender];
}

-(void)btnAction:(UIButton*)sender{
    [self.delagate DKUnauthorizedProductSelectedIndex:sender.tag];
    switch (sender.tag) {
        case 1:{
            self.applicationBtn.selected = YES;
            self.billBtn.selected = NO;
            self.historyBtn.selected = NO;
        }
            break;
        case 2:{
            self.applicationBtn.selected = NO;
            self.billBtn.selected = YES;
            self.historyBtn.selected = NO;
        }
            break;
        case 3:{
            self.applicationBtn.selected = NO;
            self.billBtn.selected = NO;
            self.historyBtn.selected = YES;
          
        }
            break;
        default:
            break;
    }
    
   
}

- (void)creatUI{
    [self addSubview:self.applicationBtn];
    [self.applicationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
    }];
    
    [self addSubview:self.billBtn];
    [self.billBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.applicationBtn.mas_right).offset(DK_IsWidthScale(12));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
        make.width.equalTo(self.applicationBtn.mas_width);
    }];
    
    [self addSubview:self.historyBtn];
    [self.historyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.billBtn.mas_right).offset(DK_IsWidthScale(12));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(-DK_IsWidthScale(0)));
        make.width.equalTo(self.billBtn.mas_width);
    }];
}

-(UIButton*)applicationBtn{
    if (!_applicationBtn) {
        _applicationBtn = [[UIButton alloc] init];
        [_applicationBtn setBackgroundImage:[UIImage imageNamed:@"dk_productNoSelect"] forState:UIControlStateNormal];
        [_applicationBtn setBackgroundImage:[UIImage imageNamed:@"dk_productSelect"] forState:UIControlStateSelected];
        [_applicationBtn setImage:[UIImage imageNamed:@"dk_productApplication_h"] forState:UIControlStateNormal];
        [_applicationBtn setImage:[UIImage imageNamed:@"dk_productApplication"] forState:UIControlStateSelected];
        _applicationBtn.selected = YES;
        _applicationBtn.tag = 1;
        [_applicationBtn addTarget:self  action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _applicationBtn;
}

-(UIButton*)billBtn{
    if (!_billBtn) {
        _billBtn = [[UIButton alloc] init];
        [_billBtn setBackgroundImage:[UIImage imageNamed:@"dk_productNoSelect"] forState:UIControlStateNormal];
        [_billBtn setBackgroundImage:[UIImage imageNamed:@"dk_productSelect"] forState:UIControlStateSelected];
        [_billBtn setImage:[UIImage imageNamed:@"dk_productBills"] forState:UIControlStateNormal];
        [_billBtn setImage:[UIImage imageNamed:@"dk_productBills_no"] forState:UIControlStateSelected];
        _billBtn.tag = 2;
        [_billBtn addTarget:self  action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _billBtn;
}

-(UIButton*)historyBtn{
    if (!_historyBtn) {
        _historyBtn = [[UIButton alloc] init];
        [_historyBtn setBackgroundImage:[UIImage imageNamed:@"dk_productNoSelect"] forState:UIControlStateNormal];
        [_historyBtn setBackgroundImage:[UIImage imageNamed:@"dk_productSelect"] forState:UIControlStateSelected];
        [_historyBtn setImage:[UIImage imageNamed:@"dk_productHistory"] forState:UIControlStateNormal];
        [_historyBtn setImage:[UIImage imageNamed:@"dk_productHistory_h"] forState:UIControlStateSelected];
        _historyBtn.tag = 3;
        [_historyBtn addTarget:self  action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _historyBtn;
}

@end
